<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<meta charset="utf-8" />
	<title></title>
	<link href="../css/bootstrap.min.css" rel="stylesheet">
	<link href="../css/bootstrap-select.css" rel="stylesheet">
    <link rel="stylesheet" href="../css/bootstrap-datetimepicker.min.css">
    <link rel="stylesheet" href="../css/bootstrap-treeview.min.css">
	<link href="../css/font-awesome.min.css" rel="stylesheet">
	<link href="../css/JyyCommon.css" rel="stylesheet">
	<link href="../css/JyyTable.css" rel="stylesheet">
	<link href="../css/JyyTree.css" rel="stylesheet">
	<link href="../css/JyyMsgBox.css" rel="stylesheet">
	<script type="text/javascript" src="../js/jquery-3.2.1.js"></script>
	<script type="text/javascript" src="../js/jquery.form.min.js"></script> 
	<script type="text/javascript" src="../js/jquery-ui.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap-datetimepicker.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap-paginator.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap-treeview.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap-select.js"></script>
	<script type="text/javascript" src="../js/jyy_modal.js"></script>
	<script type="text/javascript" src="../js/JyyCommon.js"></script>
	<script type="text/javascript" src="../js/JyyTable.js"></script>
	<script type="text/javascript" src="../js/JyyTree.js"></script>
	<script type="text/javascript" src="../js/JyyMsgBox.js"></script>
	<script type="text/javascript" src="../js/JyyLoading.js"></script>
	<script type="text/javascript" src="../js/echarts.js"></script>
	<style>
	.heidenbt{
		display: none
	}
</style>
	<script type="text/javascript">
		var tree = null;
		var projectId =  getQueryString("projectId")||'88888888888';
		$(function(){
			getDatePicker();
			getSelectDatas();
		});
		function selectData(){
			var dateSel =  $('#dateSel').val(); 
			var pvstation =  $('#pvstation').val();
			if(JyyCommon.isEmpty(dateSel)){
				JyyMsgBox.alert({ title:"警告", message:"[日期]不可为空",type:"warning"}).on(function (e) {});
				return false;
			}
			if(pvstation.length == 0){
				JyyMsgBox.alert({ title:"警告", message:"[光伏电站]不可为空",type:"warning"}).on(function (e) {});
				return false;
			}
			JyyModelLoading.start("pvStationEchartDiv");
			$.when(getEcahtData(dateSel, pvstation, "selectPvStationEchatData")).done(function(echatData){
				createEchat(echatData, 1);
				JyyModelLoading.end("pvStationEchartDiv");
			});
			JyyModelLoading.start("monthEchartDiv");
			$.when(getEcahtData(dateSel, pvstation, "selectPvStationMonthEchatData")).done(function(echatData){
				createEchat(echatData, 2);
				JyyModelLoading.end("monthEchartDiv");
			});
			JyyModelLoading.start("yearEchartDiv");
			$.when(getEcahtData(dateSel, pvstation, "selectPvStationYearEchatData")).done(function(echatData){
				createEchat(echatData, 3);
				JyyModelLoading.end("yearEchartDiv");
			});
		}

		function selectData1(){
			var yearSel =  $('#yearSel').val(); 
			var monthSel =  $('#monthSel').val(); 
			var pvstation1 =  $('#pvstation1').val();
			if(JyyCommon.isEmpty(yearSel) || JyyCommon.isEmpty(monthSel)){
				JyyMsgBox.alert({ title:"警告", message:"[年月]不可为空",type:"warning"}).on(function (e) {});
				return false;
			}
			if(pvstation1.length == 0){
				JyyMsgBox.alert({ title:"警告", message:"[光伏电站]不可为空",type:"warning"}).on(function (e) {});
				return false;
			}
			JyyModelLoading.start("yearProEchartDiv");
			$.when(getEcahtData1(yearSel,monthSel, pvstation1, "selectPVYearProEchatData")).done(function(echatData){
				createEchat(echatData, 4);
				JyyModelLoading.end("yearProEchartDiv");
			});
			JyyModelLoading.start("monthProEchartDiv");
			$.when(getEcahtData1(yearSel,monthSel, pvstation1, "selectPVMonthProEchatData")).done(function(echatData){
				createEchat(echatData, 5);
				JyyModelLoading.end("monthProEchartDiv");
			});
		}
		function createEchat(echartData, code) {
			var id = "";
			var option = {};
			var xAxisName = "";
			var yAxisName = "MW";
			if(code == 1) {
				id = "pvStationEchart";
				xAxisName = "时刻";
			} else if(code == 2) {
				id = "monthEchart";
				xAxisName = "日";
				yAxisName = "MWh";
			} else if(code == 3) {
				id = "yearEchart";
				xAxisName = "月份";
				yAxisName = "MWh";
			} else if(code == 4) {
				id = "yearProEchart";
				xAxisName = "出力率";
				yAxisName = "概率";
			} else if(code == 5) {
				id = "monthProEchart";
				xAxisName = "出力率";
				yAxisName = "概率";
			}
			var xAxisData = echartData.xAxisData;
			var seriesData = [];
			for(var i = 0; i < echartData.seriesData.length;i++) {
				seriesData.push({
					name: echartData.seriesData[i].name,
					type: 'line',
				    data: echartData.seriesData[i].series
				});
			}
			option = {
			  	tooltip: {
			    	trigger: 'axis',
			    	axisPointer: {
			      		type: 'cross',
			      		label: {
			        		backgroundColor: '#6a7985'
			      		}
			    	},
			    	position: function(point, params, dom, rect, size) {
			             //其中point为当前鼠标的位置，size中有两个属性：viewSize和contentSize，分别为外层div和tooltip提示框的大小
			             var x = point[0]; //
			             var y = point[1];
			             var viewWidth = size.viewSize[0];
			             var viewHeight = size.viewSize[1];
			             var boxWidth = size.contentSize[0];
			             var boxHeight = size.contentSize[1];
			             var posX = 0; //x坐标位置
			             var posY = 0; //y坐标位置

			             if (x < boxWidth) { //左边放不开
			                 posX = 5;
			             } else { //左边放的下
			                 posX = x - boxWidth;
			             }

			             if (y < boxHeight) { //上边放不开
			                 posY = 5;
			             } else { //上边放得下
			                 posY = y - boxHeight;
			             }

			             return [posX, posY];
			         }
			  	},
				toolbox: {
					show: true,
					right: 30,
				    itemSize: 18,
					itemGap: 12,
			        feature: {
			        	myTool: {
			        		show: true,
			        		title: "导出为Excel",
			        		icon: 'image://../images/export.png',
			        		onclick: (o) => {
								var option = o.option;
								var dataSource = [];
								var dataType = "\uFEFF"; //解决乱码问题
								dataType += option.xAxis[0].name+",";  //添加表格的头
								if(option.series.length > 0) {
									for(var i = 0;i < option.series.length;i++) {
										dataType += option.series[i].name+","
									}
									dataType = dataType.substr(0, dataType.length-1)
								}
								dataType += '\n'; // 以上是导出的Excel文件头部

								for(var i = 0;i < option.xAxis[0].data.length;i++) {
									var arr = [];
									for(var j = 0;j < option.series.length+1;j++) {
										if(j == 0) {
											arr.push(option.xAxis[0].data[i]);
										} else {
											arr.push(option.series[j-1].data[i]);
										}
									}
									dataSource.push(arr);
								}
								// 从dataSource中取出数据存入数据源（dataType）
								dataSource.map(item => dataType += `${item.join(',')}\n`); 
								// 使用Blob，获得二进制实例
								const csvData = new Blob([dataType], {
								    type: 'text/csv'
								});
								// 创建a标签
								const _a = document.createElement('a');
								_a.href = URL.createObjectURL(csvData);
								_a.target = '_blank';
								_a.download = `echartsData.csv`;
								document.body.appendChild(_a);
								_a.click();
								document.body.removeChild(_a);
		                   	},
			        	},
			        	saveAsImage: {}
			        }
			    },
			  	grid: {
			    	left: '3%',
			    	right: '8%',
			    	bottom: '3%',
			    	containLabel: true
			  	},
			  	xAxis: [{
			    	type: 'category',
			    	name: xAxisName,
			      	boundaryGap: false,
			      	data: xAxisData
			    }],
			  	yAxis: [{
			      	type: 'value',
			      	name: yAxisName
			    }],
				legend: {},
			  	series: seriesData
			};
			var chartDom = document.getElementById(id);
			var myChart = echarts.init(chartDom);
			myChart.clear();
			myChart.setOption(option);
		    window.addEventListener("resize", () => {
		        if(myChart){
		          myChart.resize()
		        }
	    	})
		}
		
		//查询
		function select(){
			selectData();
		}

		//查询1
		function select1(){
			selectData1();
		}
		function getQueryString (name){
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			return r ? unescape(r[2]) : null;
		}

		function getDatePicker(){
			$.ajax({
				url: "../g/service/Sample/selectPVPowerDate",
				type:'POST',
				cache:false,
				dataType: "json",
				data:JSON.stringify({ projectId : projectId }),
				contentType:"application/json",
	            success:function(data){
	            	if(!data.readOnly){
		    			$("#dateSel").datetimepicker({
		    				format : 'yyyy-mm-dd', // 展现格式
		    				autoclose : true, // 选择日期后关闭
		    				language : 'zh-CN', //显示语言为中文
		    				minView : "2",
		    				startDate : new Date(data.startDate),
		    				endDate : new Date(data.endDate)
		    			});
		    			$("#dateSel").datetimepicker("setDate", new Date(data.startDate));
		            	selectData();
	            	} else {
		    			$("#dateSel").datetimepicker({
		    				format : 'yyyy-mm-dd', // 展现格式
		    				autoclose : true, // 选择日期后关闭
		    				language : 'zh-CN', //显示语言为中文
		    				minView : "2",
		    				startDate : new Date(),
		    				endDate : new Date()-1000*60*60*24
		    			});
						JyyMsgBox.alert({ title:"警告", message:"暂无相关数据",type:"warning"}).on(function (e) {});
	            	}
	            	selectData1();
	            }
			});
		}

		function getSelectDatas(){
			$.ajax({
				url: "../g/service/Sample/getPvStation",
				type:'POST',
				async:false,
				dataType: "json",
				data:JSON.stringify({ projectId : projectId }),
				contentType:"application/json",
		        success:function(data){
					var content = '';
					$.each(data.pvstation,function(i,n){
						if(i == 0){
							content += "<option value='" + n + "' selected>"+ n+"</option>";
						} else {
							content += "<option value='" + n + "'>"+ n+"</option>";
						}
					});
					$("#pvstation").html(content);

					var content1 = '';
					$.each(data.pvstation1,function(i,n){
						if(i == 0){
							content1 += "<option value='" + n + "' selected>"+ n+"</option>";
						} else {
							content1 += "<option value='" + n + "'>"+ n+"</option>";
						}
					});
					$("#pvstation1").html(content1);

					var content2 = '';
					$.each(data.iyear,function(i,n){
						content2 += "<option value='" + n + "'>"+ n+"</option>";
					});
					$("#yearSel").html(content2);
					$('.selectpicker').selectpicker('refresh');
		        }
			});
		}
		
		function getEcahtData(date, pvstation, method){
			var res = $.ajax({
				url: "../g/service/Sample/"+method,
				type:'POST',
				cache:false,
				dataType: "json",
				data:JSON.stringify({ projectId : projectId, date : date, pvstation:pvstation }),
				contentType:"application/json",
	            success:function(data){
					return data;
	            }
			});
			return res;
		}

		function getEcahtData1(yearSel,monthSel, pvstation, method){
			var res = $.ajax({
				url: "../g/service/Sample/"+method,
				type:'POST',
				cache:false,
				dataType: "json",
				data:JSON.stringify({ projectId : projectId, yearSel:yearSel,monthSel:monthSel, pvstation:pvstation }),
				contentType:"application/json",
	            success:function(data){
					return data;
	            }
			});
			return res;
		}
		function invoke(url, args, callback){
			var r, op = {
					url: '../g/service/Sample/' + url,
					type:'POST',
					cache:false,
					async:true,
					dataType:'json',
					data:args ? JSON.stringify(args) : null,
					contentType:"application/json"
				};
			if(typeof callback == 'function'){
				op.success = function(data){
					if(data.error)return alert(data.error);
					callback(data);
				}
			} else {
				op.async = false;
				op.success = function(data){
					r = data
				};
			}
			$.ajax(op);
			if(r)if(r.error){
				alert(r.error);
				return null;
			}
			return r;
		};
	</script>
<style type="text/css">
	body, html{
		width: 100%;
		height: 100%;
	}
	.selBtn {
		float:left;
		margin-left:20px;
		height:30px;
		width:70px;
		background-color:#1890FF;
		border-radius:5px;
		border: 0px;
		color:white;
	}
	.selBtn:hover {
		background-color: #00BFFF;
	}
	.shadow {
		box-shadow: 0 0.05rem 1rem rgba(0,0,0,0.15)!important;
		border-radius: 0.25rem!important;
		margin-left: 20px;
		margin-bottom: 20px;
	}
	.bootstrap-select:not(.input-group-btn), .bootstrap-select[class*="col-"] {
		float: left;
	}
</style>
</head>
<body>
<div style="overflow-y: auto;width: 100%;height: 100%;">
	<div style="height: 50px;width: calc(100% - 20px);">
		<div class="col-md-12" style="padding-left: 5px;padding-right: 5px;margin-top: 10px;margin-left: 20px;">
			<label  class="control-label col-sm-1" style="float: left;margin-top: 7px;padding: 0px;width: 40px;font-weight: normal;">日期</label>
            <input id="dateSel" class="form-control" placeholder="请选择日期" readonly style="float: left;margin-top: -3px;padding: 5px;width: 184px;font-weight: normal;">
			<label  class="control-label col-sm-1" style="float: left;margin-top: 7px;margin-left: 20px;padding: 0px;width: 60px;font-weight: normal;">光伏电站</label>
			<select class="form-control selectpicker" multiple data-live-search="true" data-actions-box="true" data-selected-text-format="count > 4"
					id="pvstation" title="请选择光伏电站" data-none-results-text="未找到相关光伏电站{0}" data-select-all-text="全选" data-deselect-all-text="取消全选"
					data-width="250px" data-size="10" data-count-selected-text="已选择{1}个光伏电站中的{0}个"></select>

			<button class="selBtn" onclick=select()>查询</button>
		</div>
	</div>
	<div id="pvStationEchartDiv" class="shadow" style="width: calc(100% - 40px);min-height: 450px;position: relative;">
		<p style="margin-top: 10px;padding-top: 10px;">
			<span style="color: #1890FF;font-weight: 700;font-size: 16px;margin-left: 20px;font-family: '黑体 Bold', '黑体';">光伏电站出力情况</span>
		</p>
		<div id="pvStationEchart" style="width: 100%;height: 400px;margin-top: 25px;"></div>
	</div>
	<div id="monthEchartDiv" class="shadow" style="width: calc(100% - 40px);min-height: 450px;position: relative;">
		<p style="margin-top: 10px;padding-top: 10px;">
			<span style="color: #1890FF;font-weight: 700;font-size: 16px;margin-left: 20px;font-family: '黑体 Bold', '黑体';">光伏电站月发电量情况</span>
		</p>
		<div id="monthEchart" style="width: 100%;height: 400px;margin-top: 25px;"></div>
	</div>
	<div id="yearEchartDiv" class="shadow" style="width: calc(100% - 40px);min-height: 450px;position: relative;margin-bottom: 0px;">
		<p style="margin-top: 10px;padding-top: 10px;">
			<span style="color: #1890FF;font-weight: 700;font-size: 16px;margin-left: 20px;font-family: '黑体 Bold', '黑体';">光伏电站年发电量情况</span>
		</p>
		<div id="yearEchart" style="width: 100%;height: 400px;margin-top: 25px;"></div>
	</div>
	
	<div style="height: 50px;margin-top: 10px;width: calc(100% - 20px);">
		<div class="col-md-12" style="margin-top: 10px;padding-left: 5px;padding-right: 5px;margin-left: 20px;">
			<label  class="control-label col-sm-1" style="float: left;margin-top: 7px;padding: 0px;width: 30px;font-weight: normal;">年</label>
			<select class="form-control" id="yearSel" style="float: left;margin-top: -3px;padding: 5px;width: 120px;font-weight: normal;"></select>
			
			<label  class="control-label col-sm-1" style="float: left;margin-top: 7px;margin-left: 20px;padding: 0px;width: 30px;font-weight: normal;">月</label>
			<select class="form-control selectpicker" multiple data-actions-box="true" data-selected-text-format="count > 5"
					title="请选择月" data-select-all-text="全选" data-deselect-all-text="取消全选" id="monthSel" 
					data-width="180px" data-size="10" data-count-selected-text="已选择{1}个月中的{0}个">
				<option value="1" selected>1月</option>
				<option value="2">2月</option>
				<option value="3">3月</option>
				<option value="4">4月</option>
				<option value="5">5月</option>
				<option value="6">6月</option>
				<option value="7">7月</option>
				<option value="8">8月</option>
				<option value="9">9月</option>
				<option value="10">10月</option>
				<option value="11">11月</option>
				<option value="12">12月</option>
			</select>
			
			<label  class="control-label col-sm-1" style="float: left;margin-top: 7px;margin-left: 20px;padding: 0px;width: 60px;font-weight: normal;">光伏电站</label>
			<select class="form-control selectpicker" multiple data-live-search="true" data-actions-box="true" data-selected-text-format="count > 4"
					title="请选择光伏电站" data-none-results-text="未找到相关光伏电站{0}" data-select-all-text="全选" data-deselect-all-text="取消全选" id="pvstation1" 
					data-width="250px" data-size="10" data-count-selected-text="已选择{1}个光伏电站中的{0}个"></select>

			<button class="selBtn" onclick=select1()>查询</button>
		</div>
	</div>
	<div id="yearProEchartDiv" class="shadow" style="width: calc(100% - 40px);min-height: 450px;position: relative;">
		<p style="margin-top: 10px;padding-top: 10px;">
			<span style="color: #1890FF;font-weight: 700;font-size: 16px;margin-left: 20px;font-family: '黑体 Bold', '黑体';">光伏电站年出力概率统计</span>
		</p>
		<div id="yearProEchart" style="width: 100%;height: 400px;margin-top: 25px;"></div>
	</div>
	<div id="monthProEchartDiv" class="shadow" style="width: calc(100% - 40px);min-height: 450px;position: relative;">
		<p style="margin-top: 10px;padding-top: 10px;">
			<span style="color: #1890FF;font-weight: 700;font-size: 16px;margin-left: 20px;font-family: '黑体 Bold', '黑体';">光伏电站月出力概率统计</span>
		</p>
		<div id="monthProEchart" style="width: 100%;height: 400px;margin-top: 25px;"></div>
	</div>
</div>
</body>
</html>